<style>.upload-item{position: relative;}.delitem{width: 30px;line-height: 15px;text-align: center;font-size: 12px;position: absolute;top: 0;right: 0;color: #fff;background-color: #f32323;padding: 2px;border-radius: 3px;z-index: 100;}</style>
<div>
    <div class="upload-wrap flex-wrap flex-row flex-justify-start flex-align-center">
        <?php foreach ($originval as $v):?>
        <div class="upload-item">
            <div class="preview">
                <?php if (!empty($v)):?>
                <img src="<?php echo $v;?>" style="height:100px">
                <?php endif;?>
            </div>
            <div class="delitem">删除</div>
            <input class="fileupload_<?php echo $ckey;?>" type="file" name="<?php echo $ckey;?>[]" style="border: none;width: auto;max-width: 150px;" req="<?php echo $request;?>">
        </div>
        <?php endforeach;?>
    </div>
    <div class="button" id="addimage">新增</div>
</div>

<script type="text/javascript">
    $(document).on("change",".fileupload_<?php echo $ckey;?>",function(e){
        var preview = $(this).parent().find(".preview");
        var files = e.target.files||e.dataTransfer.files;
        for(var i=0;i<files.length;i++){
            /*检查图片大小和类型*/
            if(files[i]){
                var filesize=Math.round(files[i].size/1024/1024*100)/100;/*单位MB*/
                if(filesize>5){
                    alert('图片应小于5M');
                }else{
                    /*为此次添加的文件创建base64码*/
                    var reader = new FileReader();
                    reader.readAsDataURL(files[i]);
                    reader.onload=function(){
                        /*生成缩略图*/
                        var thumbhtml="<img src='"+ this.result +"' style='height:100px;'/>";
                        preview.html(thumbhtml);
                    }
                }
            }
        }
    });
    $(document).on('click','.delitem',function () {
        $(this).parent().remove();
    });
    $('#addimage').on('click',function () {
        var html = '<div class="upload-item">' +
            '<div class="preview"></div><div class="delitem">删除</div>'+
            '<input class="fileupload_<?php echo $ckey;?>" type="file" name="<?php echo $ckey;?>[]" style="border: none;width: auto;max-width:150px;" req="<?php echo $request;?>"></div>';
        $(this).parent().find('.upload-wrap').append(html);
    });
</script>
